package com.hxc.sercurity.controller;

import com.hxc.sercurity.configu.projo.User;
import com.hxc.sercurity.service.LoginServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @author 韩先楚
 */
@RestController
public class TextController {

    @Autowired
    private LoginServiceImpl loginService;

    @PostMapping ("/login02")
    public String Login(@RequestBody User user)
    {
        return loginService.getUser(user);
    }

    @GetMapping("/index")
//    @PreAuthorize("hasAnyAuthority( 'user')")
    @PreAuthorize("@ex.hasAuthority('admin')")
    public String index()
    {
        return "index";
    }

    @RequestMapping("/hello")
//    @Secured( {"ROLE_admin", "ROLE_user"} )
    @PreAuthorize("hasAnyAuthority('ROLE_admin')")
    public String hello()
    {
        return "hello";
    }


    @GetMapping("/ajax_text")
    public String get() {
        return "Hello World!";
    }
    //退出登录
    @GetMapping("/loginout")
    public String Loginout() {
      return   loginService.Loginout();
    }

    public static void main(String[] args) {

    }

//    public static Collection<String> get01()
//    {
//        return new ArrayList<>();
//    }

}
